package com.hzlj.position.config.service.impl;

import com.fz.common.dict.annotation.DictConvert;
import com.hzlj.position.config.common.dto.jzJbxxDeviceBindHistory.JzJbxxDeviceBindHistoryAddDTO;
import com.hzlj.position.config.common.dto.jzJbxxDeviceBindHistory.JzJbxxDeviceBindHistoryQueryParamDTO;
import com.hzlj.position.config.common.dto.jzJbxxDeviceBindHistory.JzJbxxDeviceBindHistoryQueryResultDTO;
import com.hzlj.position.config.common.model.JzJbxxDeviceBindHistory;
import com.hzlj.position.config.converter.JzJbxxDeviceBindHistoryConverter;
import com.hzlj.position.config.dao.JzJbxxDeviceBindHistoryDao;
import com.hzlj.position.config.service.JzJbxxDeviceBindHistoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

import static com.hzlj.position.config.config.IdConfig.POSITION_ID_GEN;

/**
 * 设备绑定历史表(JzJbxxDeviceBindHistory)表服务接口
 *
 * @author lifh
 * @date 2023-03-30 20:52:50
 */
@Slf4j
@Service
public class JzJbxxDeviceBindHistoryServiceImpl implements JzJbxxDeviceBindHistoryService {
    @Resource
    private JzJbxxDeviceBindHistoryDao jzJbxxDeviceBindHistoryDao;

    /**
     * 新增数据
     *
     * @param dto 实例对象
     * @return 实例对象
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public JzJbxxDeviceBindHistoryQueryResultDTO saveJzJbxxDeviceBindHistory(JzJbxxDeviceBindHistoryAddDTO dto) {
        JzJbxxDeviceBindHistory jzJbxxDeviceBindHistory = JzJbxxDeviceBindHistoryConverter.from(dto);
        jzJbxxDeviceBindHistory.setId(POSITION_ID_GEN.nextIdStr());
        //新增数据
        this.jzJbxxDeviceBindHistoryDao.save(jzJbxxDeviceBindHistory);
        log.info("【新增数据成功】:jzJbxxDeviceBindHistory={}", jzJbxxDeviceBindHistory);
        return JzJbxxDeviceBindHistoryConverter.from(jzJbxxDeviceBindHistory);
    }

    /**
     * 查询列表：不分页
     *
     * @param dto 查询条件
     * @return 对象列表
     */
    @Override
    @DictConvert
    public List<JzJbxxDeviceBindHistoryQueryResultDTO> listJzJbxxDeviceBindHistory(JzJbxxDeviceBindHistoryQueryParamDTO dto) {
        return this.jzJbxxDeviceBindHistoryDao.listJzJbxxDeviceBindHistory(dto);
    }
}
